package com.prop;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.aspose.cells.CustomDocumentPropertyCollection;
import com.aspose.cells.License;
import com.aspose.cells.Workbook;
import com.aspose.words.Document;
import com.aspose.words.SaveFormat;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDDocumentInformation;
import org.apache.poi.hpsf.CustomProperties;
import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.PropertySetFactory;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.dom4j.DocumentException;
import org.ofdrw.core.basicStructure.ofd.DocBody;
import org.ofdrw.core.basicStructure.ofd.OFD;
import org.ofdrw.core.basicStructure.ofd.docInfo.CT_DocInfo;
import org.ofdrw.core.basicStructure.ofd.docInfo.CustomData;
import org.ofdrw.core.basicStructure.ofd.docInfo.CustomDatas;
import org.ofdrw.pkg.container.OFDDir;
import org.ofdrw.reader.OFDReader;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.support.PropertiesLoaderUtils;

import java.io.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.SimpleDateFormat;
import java.util.*;

//import org.ofdrw.layout.OFDDoc;
//import org.ofdrw.layout.element.Paragraph;
//import org.ofdrw.layout.element.Span;


public class FilePropertyApi {
    public static String filetype = "doc,docx,dps,et,ett,ppt,pptx,wps,xls,xlsx,zip";
    public static String fileprop = "classificationLevel,classificationDuration,classificationPeriod,declassifiedTime," +
            "durationDescription,classifiedTime,accessScope,accessDescription,classificationStatus,classificationBasis," +
            "basisDescription,basisType,classifiedOrganization,drafter,classifiedPerson,Issuer,classificationIdentifier," +
            "classificationHistory,extensions,createTime,lastSaveTime";

    /**
     * 将字节数组转换成十六进制形式的字符串
     *
     * @param bytes
     * @return
     */
    public static String bytesToHexString(byte[] bytes) {
        StringBuilder resultHexString = new StringBuilder();
        String tempStr = "";
        for (int i = 0; i < bytes.length; i++) {
            //高位清零
            tempStr = Integer.toHexString(bytes[i] & 0xff);
            if (tempStr.length() == 1) {
                resultHexString.append(0).append(tempStr);
            } else {
                resultHexString.append(tempStr);
            }
        }
        return resultHexString.toString();
    }

    /**
     * 将字符串异或得到加密的字符串
     *
     * @param str
     * @return
     */
    public static String encryptByXor(String str) {
        char[] chars = str.toCharArray();
        char key = '0';
        for (int i = 0; i < chars.length; i++) {
            chars[i] = (char) (chars[i] ^ key);
        }
        return new String(chars);
    }
    private static long findMarkerPosition(RandomAccessFile raf) throws IOException {
        String MARKER = "<!-- JSON APPEND -->";
        long fileLength = raf.length();
        long markerLength = MARKER.length();
        long position = fileLength - markerLength;

        if (position < 0) {
            // 文件比标志符还短，直接返回-1
            return -1;
        }
        int count = 0;
        // 从文件末尾向前逐字节检查标志符
        while (position >= 0) {
            raf.seek(position);

            byte[] buffer = new byte[(int) markerLength];
            raf.read(buffer);
            String chunk = new String(buffer);

            if (chunk.equals(MARKER)) {
                return position;
            }

            position--;
            count++;    // 仅循环4096次
            if (count >= 4096){
                break;
            }
        }

        return -1;
    }
    public static String detectFileType(String filePath) {
        String fileTypeByExtension = detectFileTypeByExtension(filePath);
        if (!fileTypeByExtension.equals("Unknown")) {
            return fileTypeByExtension;
        }

        return detectFileTypeByHeader(filePath);
    }

    public static boolean detectFileTypeRW(String filePath) {
        String fileTypeByExtension = detectFileTypeByExtension(filePath);
        if (!fileTypeByExtension.equals("Unknown")) {
            return true;
        }

        return false;
    }

    private static String detectFileTypeByExtension(String filePath) {
        String extension = getFileExtension(filePath);

        switch (extension.toLowerCase()) {
            case "zip":
                return "zip";
            case "7z":
                return "7z";
            case "rar":
                return "rar";
            case "jpg":
            case "jpeg":
                return "jpeg";
            case "mp4":
                return "mp4";
            case "png":
                return "png";
            case "PNG":
                return "PNG";
            case "mp3":
                return "mp3";
            default:
                return "Unknown";
        }
    }

    private static String detectFileTypeByHeader(String filePath) {
        try (FileInputStream fis = new FileInputStream(filePath)) {
            byte[] fileHeader = new byte[10];
            if (fis.read(fileHeader) != -1) {
                if (startsWith(fileHeader, new byte[]{0x50, 0x4B, 0x03, 0x04})) {
                    return "zip";
                } else if (startsWith(fileHeader, new byte[]{0x37, 0x7A, (byte) 0xBC, (byte) 0xAF, 0x27, 0x1C})) {
                    return "7z";
                } else if (startsWith(fileHeader, new byte[]{0x52, 0x61, 0x72, 0x21, 0x1A, 0x07, 0x00})) {
                    return "rar";
                } else if (startsWith(fileHeader, new byte[]{(byte) 0xFF, (byte) 0xD8, (byte) 0xFF})) {
                    return "jpeg";
                } else if (startsWith(fileHeader, new byte[]{0x00, 0x00, 0x00, 0x18, 0x66, 0x74, 0x79, 0x70}) ||
                        startsWith(fileHeader, new byte[]{0x00, 0x00, 0x00, 0x20, 0x66, 0x74, 0x79, 0x70})) {
                    return "mp4";
                } else if (startsWith(fileHeader, new byte[]{(byte) 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A})) {
                    return "png";
                } else if (startsWith(fileHeader, new byte[]{(byte) 0xFF, (byte) 0xFB}) ||
                        startsWith(fileHeader, new byte[]{0x49, 0x44, 0x33})) {
                    return "mp3";
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "Unknown";
    }

    private static String getFileExtension(String filePath) {
        File file = new File(filePath);
        String fileName = file.getName();
        int dotIndex = fileName.lastIndexOf('.');
        return (dotIndex == -1) ? "" : fileName.substring(dotIndex + 1);
    }

    private static boolean startsWith(byte[] fileHeader, byte[] magicBytes) {
        if (fileHeader.length < magicBytes.length) {
            return false;
        }
        for (int i = 0; i < magicBytes.length; i++) {
            if (fileHeader[i] != magicBytes[i]) {
                return false;
            }
        }
        return true;
    }
    public static void appendJsonToFile(String filePath, String inJson) {
        String MARKER = "<!-- JSON APPEND -->";
        try (RandomAccessFile raf = new RandomAccessFile(filePath, "rw")) {
            long markerPosition = findMarkerPosition(raf);

            if (markerPosition != -1) {
                // 定位到标志后的位置
                raf.seek(markerPosition + MARKER.length());

                // 清除标志后的旧内容
                raf.setLength(markerPosition + MARKER.length());
            } else {
                // 如果标志不存在，移动到文件末尾并写入标志
                raf.seek(raf.length());
                raf.write(MARKER.getBytes());
            }

            // 写入新的 JSON 数据
            raf.write(inJson.getBytes());
            System.out.println("JSON data added to file successfully.");
        } catch (IOException e) {
            System.err.println("Error processing file: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public static String readJsonFromFile(String filePath) throws IOException{
        String marker = "<!-- JSON APPEND -->";
        int bufferSize = 4096;
        StringBuilder sb = new StringBuilder();
        try(RandomAccessFile raf = new RandomAccessFile(filePath,"r")){
            long filelength = raf.length();
            if(filelength <= bufferSize){
                bufferSize = (int)filelength;
            }
            long postion = filelength - bufferSize;
            byte[] buffer  = new byte[bufferSize];
            raf.seek(postion);
            raf.read(buffer);
            sb.append(new String(buffer));

            //System.out.println("readJsonFromFile "+sb.toString());
            int index = sb.indexOf(marker);
            System.out.println("marker "+marker);
            System.out.println("index "+index);
            if(index != -1){
                return sb.substring(index + marker.length()).trim();
            }
        }
        return null;
    }

    /**
     * 设置文件密级属性信息
     */
    public static String setFileProperty(String filePath, String jsonstr) throws DocumentException {
        //delFileProperty(filePath);
        //解析base64

//        FileInputStream fisxml = new FileInputStream("src/main/resources/license.xml");
//        License license=new License();
//        license.setLicense(fisxml);

        try {
            //filePath = new String(new sun.misc.BASE64Decoder().decodeBuffer(filePath));
            System.out.println("[filePath]============" + filePath);
            jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(jsonstr));
            System.out.println("in setFile property ,jsonstr============" + jsonstr);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //获取配置文件里面的相关信息
        try {
            Properties properties = PropertiesLoaderUtils.loadAllProperties("app.properties");
            //文件类型
            filetype = new String(properties.getProperty("file.type").getBytes("iso-8859-1"), "gbk");
            //文件属性参数
            fileprop = new String(properties.getProperty("file.prop").getBytes("iso-8859-1"), "gbk");
        } catch (Exception e) {
            e.printStackTrace();
        }

        //log和一些准备
        File inputFile = new File(filePath);
        String fileName = inputFile.getName();
        System.out.println("fileName=============" + fileName);
        String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
        System.out.println("fileExt=============" + fileExt);
        String[] types = filetype.split(",");
        List<String> typeList = Arrays.asList(types);

        //文件后缀删选
        if (typeList.contains(fileExt)) {

            //解析文件属性
            Integer classificationLevel = null;// 文件密级
            String classificationPeriod = null;// 保密时长
            String declassifiedTime = null;// 解密时间
            String durationDescription = null;// 解密条件
            String classifiedTime = null;// 定密时间
            String accessDescription = null;// 知悉描述
            JSONArray accessList = null;// 列举式知悉
            Integer classificationStatus = null;// 状态
            JSONArray basisDescription = null;// 定密依据详情
            Integer basisType = null;//依据类型
            String classifiedOrganization = null;// 定密单位
            String drafter = null;// 起草人
            String classifiedPerson = null;// 定密责任人
            String issuer = null;// 文件签发人
            String classificationIdentifier = null;// 文件标示符
            String classificationHistory = null;// 变更历史
            String extensions = null;//扩展属性


            String[] props = fileprop.split(",");
            List<String> propList = Arrays.asList(props);
            try {
                FileInputStream fileInputStream = new FileInputStream(inputFile);
                //判断文件版本
                byte[] b = new byte[4];
                fileInputStream.read(b, 0, b.length);
                String versionValue = bytesToHexString(b);
                fileInputStream.close();
                JSONObject jsonfile = JSONObject.parseObject(jsonstr);

                if (propList.contains("classificationLevel")) {
                    classificationLevel = (Integer) jsonfile
                            .get("classificationLevel");// 密级
                    // System.out.println("classificationLevel=============" + classificationLevel);
                }
                if (propList.contains("classificationDuration")) {
                    JSONObject classificationDuration = (JSONObject) jsonfile
                            .get("classificationDuration");// 保密期限
                    classificationPeriod = (String) classificationDuration
                            .get("classificationPeriod");// 保密时长
                    declassifiedTime = (String) classificationDuration.get("declassifiedTime");// 解密时间
                    durationDescription = (String) classificationDuration
                            .get("durationDescription");// 解密条件
                    classifiedTime = (String) classificationDuration.get("classifiedTime");//定密时间
                }
                if (propList.contains("accessScope")) {
                    JSONObject accessScope = (JSONObject) jsonfile.get("accessScope");// 知悉范围
                    accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                    JSONArray accessArr = (JSONArray) accessScope.get("accessList");
                    accessList = accessArr;// 列举式知悉
                    //accessList = accessListArr;
                }
                if (propList.contains("classificationStatus")) {
                    classificationStatus = (Integer) jsonfile
                            .get("classificationStatus");// 状态
                }
                if (propList.contains("classificationBasis")) {
                    JSONObject classificationBasis = (JSONObject) jsonfile
                            .get("classificationBasis");// 定密依据
                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                            .get("basisDescription");// 定密依据详情
                    basisDescription = basisDescriptionArr;

                    basisType = (Integer) classificationBasis
                            .get("basisType");// 依据类型
                }
                if (propList.contains("classifiedOrganization")) {
                    JSONArray classifiedOrganizationArr = (JSONArray) jsonfile
                            .get("classifiedOrganization");// 定密单位
                    classifiedOrganization = classifiedOrganizationArr.toString();
                }
                if (propList.contains("drafter")) {
                    drafter = (String) jsonfile.get("drafter");// 起草人

                }
                if (propList.contains("classifiedPerson")) {
                    classifiedPerson = (String) jsonfile.get("classifiedPerson");// 定密责任人
                }
                if (propList.contains("Issuer")) {
                    issuer = (String) jsonfile.get("Issuer");// 文件签发人
                }
                if (propList.contains("classificationIdentifier")) {
                    classificationIdentifier = (String) jsonfile
                            .get("classificationIdentifier");// 文件标示符
                }
                if (propList.contains("classificationHistory")) {
                    JSONArray classificationHistoryArr = (JSONArray) jsonfile
                            .get("classificationHistory");// 变更历史
                    classificationHistory = classificationHistoryArr.toString();
                }
                if (propList.contains("extensions")) {
                    JSONArray extensionsArr = (JSONArray) jsonfile
                            .get("extensions");// 扩展属性
                    extensions = extensionsArr.toString();
                }


                Property property = new Property();
                property.setClassificationLevel(classificationLevel);

                //保密期限

                if (null != classificationPeriod || null != declassifiedTime || null != durationDescription || null != classifiedTime) {
                    ClassificationDuration classificationDuration = new ClassificationDuration();
                    classificationDuration.setClassificationPeriod(classificationPeriod);
                    classificationDuration.setDeclassifiedTime(declassifiedTime);
                    classificationDuration.setDurationDescription(durationDescription);
                    classificationDuration.setClassifiedTime(classifiedTime);
                    property.setClassificationDuration(classificationDuration);
                }
                //定密依据
                if (null != basisDescription || null != basisType) {
                    ClassificationBasis classificationBasis = new ClassificationBasis();
                    classificationBasis.setBasisDescription(basisDescription);
                    classificationBasis.setBasisType(basisType);
                    property.setClassificationBasis(classificationBasis);
                }
                //知悉范围
                if (null != accessDescription || null != accessList) {
                    AccessScope accessScope = new AccessScope();
                    accessScope.setAccessDescription(accessDescription);
                    accessScope.setAccessList(accessList);
                    property.setAccessScope(accessScope);
                }
                //密级属性
//        property.setClassificationPeriod(classificationPeriod);
//        property.setDeclassifiedTime(declassifiedTime);
//        property.setDurationDescription(durationDescription);
//        property.setClassifiedTime(classifiedTime);
//        property.setAccessDescription(accessDescription);
//        property.setAccessList(accessList);
                property.setClassificationStatus(classificationStatus);
//        property.setBasisDescription(basisDescription);
//        property.setBasisType(basisType);
                property.setClassifiedOrganization(classifiedOrganization);
                property.setDrafter(drafter);
                property.setClassifiedPerson(classifiedPerson);
                property.setIssuer(issuer);
                property.setClassificationIdentifier(classificationIdentifier);
                property.setClassificationHistory(classificationHistory);
                property.setExtensions(extensions);

                String jsonStr = JSON.toJSONString(property);
                jsonfile = JSONObject.parseObject(jsonStr);



                //对各类Office文件进行处理
                FileInputStream fis = new FileInputStream(inputFile);
                if (("wps".equals(fileExt)) || ("doc".equals(fileExt)) || ("docx".equals(fileExt))) {
                    //
                    // 处理doc格式的文档，处理wps格式也可以使用
                    //
                    fis.close();
                    InputStream AsposeLicenseFile = new ClassPathResource("license.xml").getInputStream();
                    com.aspose.words.License license = new com.aspose.words.License() ;
                    license.setLicense(AsposeLicenseFile);                    
                    Document document =  new Document(filePath);

                    Date createTime = document.getBuiltInDocumentProperties().getCreatedTime();
                    Date lastSaveTime = document.getBuiltInDocumentProperties().getLastSavedTime();

                    //document.getBuiltInDocumentProperties().set
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                    String createTimestr = dateFormat.format(createTime);
                    String lastSaveTimestr = dateFormat.format(lastSaveTime);

                    jsonfile.put("createTime", createTimestr);
                    jsonfile.put("lastSaveTime", lastSaveTimestr);
                    jsonstr = jsonfile.toJSONString();
                    jsonstr = encryptByXor(jsonstr);
                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
                    System.out.println(jsonstr);
                    int chunkSize=200;
                    List<String> jsonstrs=new ArrayList<>();
                    int jsonstrLength=jsonstr.length();
                    int jsonstrGroup=jsonstrLength/chunkSize;
                    int i=0;
                    for(i=0;i<jsonstrGroup;i++)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
                        jsonstrs.add(chunk);
                    }
                    int remaining_bytes=jsonstrLength%chunkSize;
                    if(remaining_bytes>0)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
                        jsonstrs.add(chunk);
                    }
                    // 填充自定义属性
					document.getCustomDocumentProperties().clear();                    
                    for(int j=0;j<jsonstrs.size();j++)
                    {
                       try {
                            //清空文档摘要信息
                            document.getCustomDocumentProperties().remove("classification"+Integer.toString(j));
                        } catch (Exception e) {
                            //throw new RuntimeException(e);
                        }
                        document.getCustomDocumentProperties().add("classification"+Integer.toString(j),jsonstrs.get(j));
                    }


                    // 保存文档属性
                    if(fileExt.equals("docx"))
                        document.save(filePath, SaveFormat.DOCX);
                    else
                        document.save(filePath, SaveFormat.DOC);
                    //document.cleanup();
                    //FileOutputStream fos = new FileOutputStream(filePath);
                    //document.save(fos);
                    document.cleanup();
                    //fos.close();

                }
//                else if ("504b0304".equals(versionValue) && ("docx".equals(fileExt) || "doc".equals(fileExt))) {
//                    XWPFDocument docxFile = new XWPFDocument(fis);
//                    Date createTime = docxFile.getProperties().getCoreProperties().getCreated();
//                    Date lastSaveTime = docxFile.getProperties().getCoreProperties().getModified();
//
//                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    String createTimestr = dateFormat.format(createTime);
//                    String lastSaveTimestr = dateFormat.format(lastSaveTime);
//
//
//                    jsonfile.put("createTime", createTimestr);
//                    jsonfile.put("lastSaveTime", lastSaveTimestr);
//                    jsonstr = jsonfile.toJSONString();
//                    jsonstr = encryptByXor(jsonstr);
//                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
//                    System.out.println(jsonstr);
//
//                    int chunkSize=200;
//                    List<String> jsonstrs=new ArrayList<>();
//                    int jsonstrLength=jsonstr.length();
//                    int jsonstrGroup=jsonstrLength/chunkSize;
//                    int i=0;
//                    for(i=0;i<jsonstrGroup;i++)
//                    {
//                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
//                        jsonstrs.add(chunk);
//                    }
//                    int remaining_bytes=jsonstrLength%chunkSize;
//                    if(remaining_bytes>0)
//                    {
//                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
//                        jsonstrs.add(chunk);
//                    }
//                    // 填充自定义属性
//                    CustomProperties castime = new CustomProperties();
//                    for(int j=0;j<jsonstrs.size();j++)
//                    {
//                        if (docxFile.getProperties().getCustomProperties().contains("classification"+Integer.toString(j))) {
//                            docxFile.getProperties().getCustomProperties().getProperty("classification"+Integer.toString(j)).setLpwstr(jsonstrs.get(j));
//                        } else {
//                            docxFile.getProperties().getCustomProperties()
//                                    .addProperty("classification"+Integer.toString(j), jsonstrs.get(j));
//                        }
//                        //castime.put("classification"+Integer.toString(j), jsonstrs.get(j));
//                    }
//
//                    // 保存文档属性
//                    FileOutputStream fos = new FileOutputStream(filePath);
//                    docxFile.write(fos);
//                    fos.close();
//                }
                else if ("dps".equals(fileExt)) {
                    HSLFSlideShow dpsFile = new HSLFSlideShow(fis);


                    SummaryInformation summary = dpsFile.getSummaryInformation();
                    Date createTime = dpsFile.getSummaryInformation().getCreateDateTime();
                    Date lastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(createTime);
                    String lastSaveTimestr = dateFormat.format(lastSaveTime);

                    jsonfile.put("createTime", createTimestr);
                    jsonfile.put("lastSaveTime", lastSaveTimestr);
                    jsonstr = jsonfile.toJSONString();
                    System.out.println(jsonstr);
                    jsonstr = encryptByXor(jsonstr);
                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
                    System.out.println(jsonstr);

                    int chunkSize=200;
                    List<String> jsonstrs=new ArrayList<>();
                    int jsonstrLength=jsonstr.length();
                    int jsonstrGroup=jsonstrLength/chunkSize;
                    int i=0;
                    for(i=0;i<jsonstrGroup;i++)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
                        jsonstrs.add(chunk);
                    }
                    int remaining_bytes=jsonstrLength%chunkSize;
                    if(remaining_bytes>0)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
                        jsonstrs.add(chunk);
                    }
                    // 填充自定义属性
                    CustomProperties castime = new CustomProperties();
                    for(int j=0;j<jsonstrs.size();j++)
                    {
                        castime.put("classification"+Integer.toString(j), jsonstrs.get(j));
                    }



                    DocumentSummaryInformation summaryInformation = PropertySetFactory
                            .newDocumentSummaryInformation();
                    summaryInformation.setCustomProperties(castime);

                    try {
                        //清空文档摘要信息
                        dpsFile.getDocumentSummaryInformation().removeCustomProperties();
                    } catch (Exception e) {
                    }

                    // 设置文档摘要信息
                    dpsFile.getDocumentSummaryInformation().setCustomProperties(summaryInformation.getCustomProperties());

                    // 保存文档属性
                    FileOutputStream fos = new FileOutputStream(filePath);
                    dpsFile.write(fos);

                    fos.close();

                }
                else if ("ett".equals(fileExt)) {
                    HSSFWorkbook etfile = new HSSFWorkbook(fis);


                    SummaryInformation summary = etfile.getSummaryInformation();
                    Date createTime = etfile.getSummaryInformation().getCreateDateTime();
                    Date lastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(createTime);
                    String lastSaveTimestr = dateFormat.format(lastSaveTime);

                    jsonfile.put("createTime", createTimestr);
                    jsonfile.put("lastSaveTime", lastSaveTimestr);
                    jsonstr = jsonfile.toJSONString();
                    System.out.println(jsonstr);
                    jsonstr = encryptByXor(jsonstr);
                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
                    System.out.println(jsonstr);


                    int chunkSize=200;
                    List<String> jsonstrs=new ArrayList<>();
                    int jsonstrLength=jsonstr.length();
                    int jsonstrGroup=jsonstrLength/chunkSize;
                    int i=0;
                    for(i=0;i<jsonstrGroup;i++)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
                        jsonstrs.add(chunk);
                    }
                    int remaining_bytes=jsonstrLength%chunkSize;
                    if(remaining_bytes>0)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
                        jsonstrs.add(chunk);
                    }
                    // 填充自定义属性
                    CustomProperties castime = new CustomProperties();
                    for(int j=0;j<jsonstrs.size();j++)
                    {
                        castime.put("classification"+Integer.toString(j), jsonstrs.get(j));
                    }

                    DocumentSummaryInformation summaryInformation = PropertySetFactory
                            .newDocumentSummaryInformation();
                    summaryInformation.setCustomProperties(castime);

                    try {
                        //清空文档摘要信息
                        etfile.getDocumentSummaryInformation().removeCustomProperties();
                    } catch (Exception e) {

                    }

                    // 设置文档摘要信息
                    etfile.getDocumentSummaryInformation().setCustomProperties(summaryInformation.getCustomProperties());

                    // 保存文档属性
                    FileOutputStream fos = new FileOutputStream(filePath);
                    etfile.write(fos);

                    fos.close();

                }
                else if ("d0cf11e0".equals(versionValue) && ("ppt".equals(fileExt) || "pptx".equals(fileExt))) {
                    HSLFSlideShow pptFile = new HSLFSlideShow(fis);


                    SummaryInformation summary = pptFile.getSummaryInformation();
                    Date createTime = pptFile.getSummaryInformation().getCreateDateTime();
                    Date lastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(createTime);
                    String lastSaveTimestr = dateFormat.format(lastSaveTime);

                    jsonfile.put("createTime", createTimestr);
                    jsonfile.put("lastSaveTime", lastSaveTimestr);
                    jsonstr = jsonfile.toJSONString();
                    System.out.println(jsonstr);
                    jsonstr = encryptByXor(jsonstr);
                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
                    System.out.println(jsonstr);


                    // 填充自定义属性
                    int chunkSize=200;
                    List<String> jsonstrs=new ArrayList<>();
                    int jsonstrLength=jsonstr.length();
                    int jsonstrGroup=jsonstrLength/chunkSize;
                    int i=0;
                    for(i=0;i<jsonstrGroup;i++)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
                        jsonstrs.add(chunk);
                    }
                    int remaining_bytes=jsonstrLength%chunkSize;
                    if(remaining_bytes>0)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
                        jsonstrs.add(chunk);
                    }
                    // 填充自定义属性
                    CustomProperties castime = new CustomProperties();
                    for(int j=0;j<jsonstrs.size();j++)
                    {
                        castime.put("classification"+Integer.toString(j), jsonstrs.get(j));
                    }

                    DocumentSummaryInformation summaryInformation = PropertySetFactory
                            .newDocumentSummaryInformation();
                    summaryInformation.setCustomProperties(castime);

                    try {
                        //清空文档摘要信息
                        pptFile.getDocumentSummaryInformation().removeCustomProperties();
                    } catch (Exception e) {

                    }

                    // 设置文档摘要信息
                    pptFile.getDocumentSummaryInformation().setCustomProperties(summaryInformation.getCustomProperties());

                    // 保存文档属性
                    FileOutputStream fos = new FileOutputStream(filePath);
                    pptFile.write(fos);

                    fos.close();


                }
                else if (!"d0cf11e0".equals(versionValue) && ("ppt".equals(fileExt) || "pptx".equals(fileExt))) {
                    XMLSlideShow pptxFile = new XMLSlideShow(fis);


                    //XWPFDocument docxFile = new XWPFDocument(fis);
                    Date createTime = pptxFile.getProperties().getCoreProperties().getCreated();
                    Date lastSaveTime = pptxFile.getProperties().getCoreProperties().getModified();

                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(createTime);
                    String lastSaveTimestr = dateFormat.format(lastSaveTime);


                    jsonfile.put("createTime", createTimestr);
                    jsonfile.put("lastSaveTime", lastSaveTimestr);
                    jsonstr = jsonfile.toJSONString();
                    System.out.println(jsonstr);
                    jsonstr = encryptByXor(jsonstr);
                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
                    System.out.println(jsonstr);
                    // 填充自定义属性
//                    CustomProperties castime = new CustomProperties();
//                    castime.put("classification", jsonstr);

                    int chunkSize=200;
                    List<String> jsonstrs=new ArrayList<>();
                    int jsonstrLength=jsonstr.length();
                    int jsonstrGroup=jsonstrLength/chunkSize;
                    int i=0;
                    for(i=0;i<jsonstrGroup;i++)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
                        jsonstrs.add(chunk);
                    }
                    int remaining_bytes=jsonstrLength%chunkSize;
                    if(remaining_bytes>0)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
                        jsonstrs.add(chunk);
                    }
                    // 填充自定义属性
                    CustomProperties castime = new CustomProperties();
                    for(int j=0;j<jsonstrs.size();j++)
                    {
                        if (pptxFile.getProperties().getCustomProperties().contains("classification"+Integer.toString(j))) {
                            pptxFile.getProperties().getCustomProperties().getProperty("classification"+Integer.toString(j)).setLpwstr(jsonstrs.get(j));
                        } else {
                            pptxFile.getProperties().getCustomProperties()
                                    .addProperty("classification"+Integer.toString(j), jsonstrs.get(j));
                        }
                        //castime.put("classification"+Integer.toString(j), jsonstrs.get(j));
                    }



                    // 保存文档属性
                    FileOutputStream fos = new FileOutputStream(filePath);
                    pptxFile.write(fos);

                    fos.close();
                }
//                else if ("wps".equals(fileExt)) {
//                    HWPFDocument wpsfile = new HWPFDocument(fis);
//
//
//                    SummaryInformation summary = wpsfile.getSummaryInformation();
//                    Date createTime = wpsfile.getSummaryInformation().getCreateDateTime();
//                    Date lastSaveTime = summary.getLastSaveDateTime();
//                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    String createTimestr = dateFormat.format(createTime);
//                    String lastSaveTimestr = dateFormat.format(lastSaveTime);
//
//                    jsonfile.put("createTime", createTimestr);
//                    jsonfile.put("lastSaveTime", lastSaveTimestr);
//                    jsonstr = jsonfile.toJSONString();
//                    System.out.println(jsonstr);
//                    jsonstr = encryptByXor(jsonstr);
//                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
//                    System.out.println(jsonstr);
//                    int chunkSize=200;
//                    List<String> jsonstrs=new ArrayList<>();
//                    int jsonstrLength=jsonstr.length();
//                    int jsonstrGroup=jsonstrLength/chunkSize;
//                    int i=0;
//                    for(i=0;i<jsonstrGroup;i++)
//                    {
//                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
//                        jsonstrs.add(chunk);
//                    }
//                    int remaining_bytes=jsonstrLength%chunkSize;
//                    if(remaining_bytes>0)
//                    {
//                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
//                        jsonstrs.add(chunk);
//                    }
//                    // 填充自定义属性
//                    CustomProperties castime = new CustomProperties();
//                    for(int j=0;j<jsonstrs.size();j++)
//                    {
//                        castime.put("classification"+Integer.toString(j), jsonstrs.get(j));
//                    }
//                    DocumentSummaryInformation summaryInformation = PropertySetFactory
//                            .newDocumentSummaryInformation();
//                    summaryInformation.setCustomProperties(castime);
//
//                    try {
//                        //清空文档摘要信息
//                        wpsfile.getDocumentSummaryInformation().removeCustomProperties();
//                    } catch (Exception e) {
//
//                    }
//
//                    // 设置文档摘要信息
//                    wpsfile.getDocumentSummaryInformation().setCustomProperties(summaryInformation.getCustomProperties());
//
//                    // 保存文档属性
//                    FileOutputStream fos = new FileOutputStream(filePath);
//                    wpsfile.write(fos);
//
//                    fos.close();
//                }
                else if ("d0cf11e0".equals(versionValue) && ("et".equals(fileExt) || "xlsx".equals(fileExt) || "xls".equals(fileExt))) {
                    HSSFWorkbook xlsfile = new HSSFWorkbook(fis);

                    SummaryInformation summary = xlsfile.getSummaryInformation();
                    Date createTime = xlsfile.getSummaryInformation().getCreateDateTime();
                    Date lastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(createTime);
                    String lastSaveTimestr = dateFormat.format(lastSaveTime);

                    jsonfile.put("createTime", createTimestr);
                    jsonfile.put("lastSaveTime", lastSaveTimestr);
                    jsonstr = jsonfile.toJSONString();
                    System.out.println(jsonstr);
                    jsonstr = encryptByXor(jsonstr);
                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
                    System.out.println(jsonstr);
                    int chunkSize=200;
                    List<String> jsonstrs=new ArrayList<>();
                    int jsonstrLength=jsonstr.length();
                    int jsonstrGroup=jsonstrLength/chunkSize;
                    int i=0;
                    for(i=0;i<jsonstrGroup;i++)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
                        jsonstrs.add(chunk);
                    }
                    int remaining_bytes=jsonstrLength%chunkSize;
                    if(remaining_bytes>0)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
                        jsonstrs.add(chunk);
                    }
                    // 填充自定义属性
                    CustomProperties castime = new CustomProperties();
                    for(int j=0;j<jsonstrs.size();j++)
                    {
                        castime.put("classification"+Integer.toString(j), jsonstrs.get(j));
                    }

                    DocumentSummaryInformation summaryInformation = PropertySetFactory
                            .newDocumentSummaryInformation();
                    summaryInformation.setCustomProperties(castime);

                    try {
                        //清空文档摘要信息
                        xlsfile.getDocumentSummaryInformation().removeCustomProperties();
                    } catch (Exception e) {

                    }

                    // 设置文档摘要信息
                    xlsfile.getDocumentSummaryInformation().setCustomProperties(summaryInformation.getCustomProperties());

                    // 保存文档属性
                    FileOutputStream fos = new FileOutputStream(filePath);
                    xlsfile.write(fos);

                    fos.close();


                }
                else if (!"d0cf11e0".equals(versionValue) && ("et".equals(fileExt) || "xlsx".equals(fileExt) || "xls".equals(fileExt))) {


                    //{
                    // 先关闭对当前文件的占用
                    fis.close();

                    // 声明Aspose授权
                    InputStream AsposeLicenseFile = new ClassPathResource("license.xml").getInputStream();
                    License license = new License();
                    license.setLicense(AsposeLicenseFile);

                    Workbook xlsxFile = new Workbook(filePath);
                    // 获取自定义属性集
                    CustomDocumentPropertyCollection customDocumentPropertyCollection = xlsxFile
                            .getCustomDocumentProperties();

                    String createTimestr = "";
                    String lastSaveTimestr = "";

                    jsonfile.put("createTime", createTimestr);
                    jsonfile.put("lastSaveTime", lastSaveTimestr);
                    jsonstr = jsonfile.toJSONString();
                    System.out.println("Get Method : " + jsonstr);
                    jsonstr = encryptByXor(jsonstr);
                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));


                    int chunkSize=200;
                    List<String> jsonstrs=new ArrayList<>();
                    int jsonstrLength=jsonstr.length();
                    int jsonstrGroup=jsonstrLength/chunkSize;
                    int i=0;
                    for(i=0;i<jsonstrGroup;i++)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
                        jsonstrs.add(chunk);
                    }
                    int remaining_bytes=jsonstrLength%chunkSize;
                    if(remaining_bytes>0)
                    {
                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
                        jsonstrs.add(chunk);
                    }
                    // 填充自定义属性
                    customDocumentPropertyCollection.clear();
                    for(int j=0;j<jsonstrs.size();j++)
                    {
                        if (customDocumentPropertyCollection.contains("classification"+Integer.toString(j))) {
                            customDocumentPropertyCollection.get("classification"+Integer.toString(j)).setValue(jsonstrs.get(j));
                        } else {
                            customDocumentPropertyCollection
                                    .add("classification"+Integer.toString(j), jsonstrs.get(j));
                        }
                    }

                    // 保存文档属性
                    xlsxFile.save(filePath);
                    AsposeLicenseFile.close();

                    //} add 使用aspose处理xlsx格式文件 by liushen



//                    XSSFWorkbook xlsxfile = new XSSFWorkbook(fis);
//
//                    Date createTime = xlsxfile.getProperties().getCoreProperties().getCreated();
//                    Date lastSaveTime = xlsxfile.getProperties().getCoreProperties().getModified();
//
//                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    String createTimestr = null;
//                    String lastSaveTimestr = dateFormat.format(lastSaveTime);
//                    if (createTime == null){
//                        createTimestr = lastSaveTimestr;
//                    }else {
//                        createTimestr  = dateFormat.format(createTime);
//                    }
//
//
//
//                    jsonfile.put("createTime", createTimestr);
//                    jsonfile.put("lastSaveTime", lastSaveTimestr);
//                    jsonstr = jsonfile.toJSONString();
//                    System.out.println(jsonstr);
//                    jsonstr = encryptByXor(jsonstr);
//                    jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
//                    System.out.println(jsonstr);
//
//
//                    int chunkSize=200;
//                    List<String> jsonstrs=new ArrayList<>();
//                    int jsonstrLength=jsonstr.length();
//                    int jsonstrGroup=jsonstrLength/chunkSize;
//                    int i=0;
//                    for(i=0;i<jsonstrGroup;i++)
//                    {
//                        String chunk=jsonstr.substring(i*chunkSize,(i+1)*chunkSize);
//                        jsonstrs.add(chunk);
//                    }
//                    int remaining_bytes=jsonstrLength%chunkSize;
//                    if(remaining_bytes>0)
//                    {
//                        String chunk=jsonstr.substring(i*chunkSize,jsonstrLength);
//                        jsonstrs.add(chunk);
//                    }
//                    // 填充自定义属性
//                    CustomProperties castime = new CustomProperties();
//                    for(int j=0;j<jsonstrs.size();j++)
//                    {
//                        if (xlsxfile.getProperties().getCustomProperties().contains("classification"+Integer.toString(j))) {
//                            xlsxfile.getProperties().getCustomProperties().getProperty("classification"+Integer.toString(j)).setLpwstr(jsonstrs.get(j));
//                        } else {
//                            xlsxfile.getProperties().getCustomProperties()
//                                    .addProperty("classification"+Integer.toString(j), jsonstrs.get(j));
//                        }
//                        //castime.put("classification"+Integer.toString(j), jsonstrs.get(j));
//                    }
//
//
//
//                    // 保存文档属性
//                    FileOutputStream fos = new FileOutputStream(filePath);
//                    xlsxfile.write(fos);
//
//                    fos.close();
                }
                else if ("pdf".equals(fileExt)) {
                    try {
                        PDDocument document = PDDocument.load(new File(filePath));

                        PDDocumentInformation info = document.getDocumentInformation();
                        //获取文件创建时间和最后一次修改时间
                        Calendar lastSaveTime = info.getModificationDate();
                        Calendar creatTime = info.getCreationDate();

                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String lastSaveTimestr = null;
                        String createTimestr=null;
                        Date date = new Date();
                        if(lastSaveTime==null)
                        {
                            lastSaveTimestr=dateFormat.format(date);
                            Calendar calendar = Calendar.getInstance();
                            calendar.setTime(date);
                            info.setModificationDate(calendar);
                        }else{
                            lastSaveTimestr = dateFormat.format(lastSaveTime.getTime());
                        }
                        if(creatTime==null)
                        {
                            createTimestr=dateFormat.format(date);
                            Calendar calendar = Calendar.getInstance();
                            calendar.setTime(date);
                            info.setCreationDate(calendar);
                        }else{
                            createTimestr = dateFormat.format(creatTime.getTime());
                        }

                        //生成自定义属性值
                        jsonfile.put("createTime", createTimestr);
                        jsonfile.put("lastSaveTime", lastSaveTimestr);
                        jsonstr = jsonfile.toJSONString();
                        System.out.println(jsonstr);
                        jsonstr = encryptByXor(jsonstr);
                        jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));

                        //设置自定义属性
                        info.setCustomMetadataValue("classification", jsonstr);
                        //保存属性信息
                        document.save(filePath);
                        document.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
                else if ("ofd".equals(fileExt)) {

                    Path srcP = Paths.get(filePath);
                    //Path outP = Paths.get("1.ofd");
                    try (OFDReader reader = new OFDReader(srcP)) {

                        //获取属性
                        CT_DocInfo ctDocInfo = reader.getOFDDir().getOfd().getDocBody().getDocInfo();
                        //获取创建时间和最后一次修改时间
                        // LocalDate creatTime = ctDocInfo.getCreationDate();
                        //LocalDate lastSaveTime = ctDocInfo.getModDate();

                        //DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                        //DateTimeFormatter formatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                        String lastSaveTimestr = "2024-01-01 10:10:10";//lastSaveTime.format(formatter);
                        String createTimestr = "2024-01-01 10:10:10";//creatTime.format(formatter1);
                        //拼接自定义属性
                        jsonfile.put("createTime", createTimestr);
                        jsonfile.put("lastSaveTime", lastSaveTimestr);
                        jsonstr = jsonfile.toJSONString();
                        System.out.println(jsonstr);
                        jsonstr = encryptByXor(jsonstr);
                        jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
                        CustomDatas customDatas = new CustomDatas();
                        customDatas.addCustomData(new CustomData("classification", jsonstr));
                        ctDocInfo.setCustomDatas(customDatas);
                        //保存到临时文件
                        reader.getOFDDir().getOfd().getDocBody().setDocInfo(ctDocInfo);

                        fis.close();
                        reader.getOFDDir().jar(Paths.get(filePath));
                        reader.close();
                        //移动到源文件并覆盖
                        //Files.move(Paths.get(".tmp.ofd"),Paths.get(filePath), StandardCopyOption.REPLACE_EXISTING);
                    } catch (DocumentException e) {
                        throw new RuntimeException(e);
                    }


//                    try (OFDReader reader = new OFDReader(srcP)) {


//                        CT_DocInfo ctDocInfo = reader.getOFDDir().getOfd().getDocBody().getDocInfo();
//                        CustomDatas customDatas = new CustomDatas();
//                        customDatas.addCustomData(new CustomData("STAG1", "128"));
//                        ctDocInfo.setCustomDatas(customDatas);
//
//                        reader.getOFDDir().getOfd().getDocBody().setDocInfo(ctDocInfo);
                    //reader.close();
//                    }

                }
                //if (null != fis && fis.available() != 0) {
                fis.close();
                // }


                //{
                /*
                * 压缩包等格式的支持
                * */
                if(detectFileTypeRW(filePath)){
                    try{
                        String lastSaveTimestr = "2024-01-01 10:10:10";//lastSaveTime.format(formatter);
                        String createTimestr = "2024-01-01 10:10:10";//creatTime.format(formatter1);
                        //拼接自定义属性
                        jsonfile.put("createTime", createTimestr);
                        jsonfile.put("lastSaveTime", lastSaveTimestr);
                        jsonstr = jsonfile.toJSONString();
                        System.out.println(jsonstr);
                        //jsonstr = encryptByXor(jsonstr);
                        jsonstr = new String(new sun.misc.BASE64Encoder().encodeBuffer(jsonstr.getBytes()));
                        appendJsonToFile(filePath,jsonstr.replaceAll("\\s*|\r|\n|\t",""));
                    }catch (Exception e){
                        e.printStackTrace();
                    }
                }
                //} add by liushen 2024-8-12



            } catch (Exception e) {
                e.printStackTrace();

                return "-2";
            }
        } else {
            return "-1";
        }

        return "0";
    }

    /**
     * 获取文件密级属性信息
     */
    public static String getFileProperty(String filePath) throws IOException {
        try {
            //filePath = new String(new sun.misc.BASE64Decoder().decodeBuffer(filePath));
            System.out.println("getFileProperty() -> filePath============" + filePath);
        } catch (Exception e) {
            e.printStackTrace();
        }
        File inputFile = new File(filePath);

        //获取配置文件里面的相关信息
        try {
            Properties properties = PropertiesLoaderUtils.loadAllProperties("app.properties");
            //文件类型
            filetype = new String(properties.getProperty("file.type").getBytes("iso-8859-1"), "gbk");
            //文件属性参数
            fileprop = new String(properties.getProperty("file.prop").getBytes("iso-8859-1"), "gbk");
        } catch (Exception e) {
            e.printStackTrace();
        }
        String[] props = fileprop.split(",");
        List<String> propList = Arrays.asList(props);

        String fileName = inputFile.getName();
        System.out.println("fileName=============" + fileName);
        String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
        System.out.println("fileExt=============" + fileExt);
        String[] types = filetype.split(",");
        List<String> typeList = Arrays.asList(types);
        //解析文件属性
        Integer classificationLevel = null;// 文件密级
        Double tmp_class = null;
        String Str_class = null;
        //String classificationDuration = null;// 保密时长
        String classificationPeriod = null;// 保密时长
        String declassifiedTime = null;// 解密时间
        String durationDescription = null;// 解密条件
        String classifiedTime = null;// 定密时间
        String accessDescription = null;// 知悉描述
        JSONArray accessList = null;// 列举式知悉
        String accessList1 = null;// 列举式知悉
        //String classificationBasis = null;//定密依据
        Integer classificationStatus = null;// 状态
        JSONArray basisDescription = null;// 定密依据详情
        Integer basisType = null;//依据类型
        String classifiedOrganization = null;// 定密单位
        String drafter = null;// 起草人
        String classifiedPerson = null;// 定密责任人
        String issuer = null;// 文件签发人
        String classificationIdentifier = null;// 文件标示符
        String classificationHistory = null;// 变更历史
        String extensions = null;//扩展属性
        String lastSaveTime = null;//最后一次保存时间
        String createTime = null;//文件创建时间
        Integer ret = -1;//是否被修改


        //{
        /*
            直接读取文件的形式,适配压缩包等类型格式
         */
        try{
            if (typeList.contains(fileExt) && detectFileTypeRW(filePath)){
                System.out.println("Path is " + filePath);
                String classification = readJsonFromFile(filePath).trim();
                System.out.println("classification is " + classification);
                String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                //String jsonstra = encryptByXor(jsonstr);
                System.out.println("----------- [" +jsonstr+"] -------------");

                JSONObject json = JSONObject.parseObject(jsonstr);
                if (propList.contains("classificationLevel")) {
                    classificationLevel = json.getInteger("classificationLevel");
                }
                if (propList.contains("classificationPeriod")) {
                    JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                    classificationPeriod = classificationDuration.getString("classificationPeriod");
                }
                if (propList.contains("declassifiedTime")) {
                    JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                    declassifiedTime = classificationDuration.getString("declassifiedTime");
                }
                if (propList.contains("durationDescription")) {
                    JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                    durationDescription = classificationDuration.getString("durationDescription");
                }
                if (propList.contains("classifiedTime")) {
                    JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                    classifiedTime = classificationDuration.getString("classifiedTime");
                }
                if (propList.contains("lastSaveTime")) {
                    lastSaveTime = json.getString("lastSaveTime");
                }
                if (propList.contains("createTime")) {
                    createTime = json.getString("createTime");
                }
//                if (propList.contains("accessDescription")) {
//                    accessDescription = json.getString("accessDescription");
//                }
                if (propList.contains("accessScope")) {
                    JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                    accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                    try{
                        accessList = (JSONArray) accessScope.get("accessList");// 列举式知悉
                    }catch (Exception e){

                    }

                }
                if (propList.contains("classificationStatus")) {
                    classificationStatus = json.getInteger("classificationStatus");
                }
                if (propList.contains("classificationBasis")) {
                    JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                    if(null!=classificationBasis){
                        try{
                            JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                    .get("basisDescription");// 定密依据详情
                            basisDescription = basisDescriptionArr;
                        } catch (Exception e) {
                            //e.printStackTrace();
                        }

                        basisType = (Integer) classificationBasis
                                .get("basisType");// 依据类型
                    }
                }
                if (propList.contains("basisType")) {
                    basisType = json.getInteger("basisType");
                }
                if (propList.contains("classifiedOrganization")) {
                    classifiedOrganization = json.getString("classifiedOrganization");
                }
                if (propList.contains("drafter")) {
                    drafter = json.getString("drafter");
                }
                if (propList.contains("classifiedPerson")) {
                    classifiedPerson = json.getString("classifiedPerson");
                }
                if (propList.contains("issuer")) {
                    issuer = json.getString("issuer");
                }
                if (propList.contains("classificationIdentifier")) {
                    classificationIdentifier = json.getString("classificationIdentifier");
                }
                if (propList.contains("classificationHistory")) {
                    classificationHistory = json.getString("classificationHistory");
                }
                if (propList.contains("extensions")) {
                    extensions = json.getString("extensions");
                }
                //文件是否被篡改判断
                ret = 0;
            }


        }catch (Exception e){
            e.printStackTrace();
        }
        //} add by liushen 2024-8-12

        //各类文件处理
        FileInputStream fileInputStream = new FileInputStream(inputFile);
        //判断文件版本
        byte[] b = new byte[4];
        fileInputStream.read(b, 0, b.length);
        String versionValue = bytesToHexString(b);
        fileInputStream.close();
        FileInputStream fis = new FileInputStream(inputFile);
        if (typeList.contains(fileExt)) {
            try {
                System.out.println("AbsolutePath=============" + inputFile.getAbsolutePath());
                //03版本文件
                if ("d0cf11e0".equals(versionValue) && ("wps".equals(fileExt) || "docx".equals(fileExt) || "doc".equals(fileExt))) {// 处理doc格式的文档，处理wps格式也可以使用
                    HWPFDocument document = new HWPFDocument(fis);

                    SummaryInformation summary = document.getSummaryInformation();
                    Date getfilecreateTime = document.getSummaryInformation().getCreateDateTime();
                    Date getfilelastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(getfilecreateTime);
                    String lastSaveTimestr = dateFormat.format(getfilelastSaveTime);
                    try {
                        DocumentSummaryInformation summaryinfomation = document.getDocumentSummaryInformation();
                        CustomProperties customproperties = summaryinfomation.getCustomProperties();

                        List<String> jsonstrs=new ArrayList<>();
                        for (int i=0;i<customproperties.size();i++)
                        {
                            String classificationList=null;
                            classificationList=(String) customproperties.get("classification"+Integer.toString(i));
                            if(null == classificationList){
                                break;
                            }
                            jsonstrs.add(classificationList);
                        }
                        String classification = "";
                        for(int j=0;j<jsonstrs.size();j++)
                        {
                            classification=classification+jsonstrs.get(j);
                        }
                        classification=classification.replace("_x000d_","");
                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);
                        JSONObject json = JSONObject.parseObject(jsonstra);
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
                        if (propList.contains("accessDescription")) {
                            JSONObject accessScope = json.getJSONObject("accessScope");
                            accessDescription = accessScope.getString("accessDescription");
                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                            accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                            try{
                                accessList = (JSONArray) accessScope.get("accessList");// 列举式知悉
                            }catch (Exception e){

                            }

                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
//                        if (propList.contains("classificationBasis")) {
//                            classificationBasis = json.getString("classificationBasis");
//                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                            .get("basisDescription");// 定密依据详情
                                    basisDescription = basisDescriptionArr;
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }
//                        if (propList.contains("basisType")) {
//                            JSONObject classificationDuration = json.getJSONObject("classificationBasis");
//                            basisType = classificationDuration.getInteger("basisType");
//                        }
                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        if (!lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;

                        }else if (!createTime.equals(createTimestr)) {
                            ret = -3;

                        }else {
                            ret = 0;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }


                }
                else if ("504b0304".equals(versionValue) && ("docx".equals(fileExt) || "doc".equals(fileExt))) {
                    XWPFDocument docxFile = new XWPFDocument(fis);

                    Date getfilecreateTime = docxFile.getProperties().getCoreProperties().getCreated();
                    Date getfilelastSaveTime = docxFile.getProperties().getCoreProperties().getModified();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(getfilecreateTime);
                    String lastSaveTimestr = dateFormat.format(getfilelastSaveTime);
                    try {

                        List<String> jsonstrs=new ArrayList<>();

                        for (int i=0;i<10;i++)
                        {

                            String classificationList= null;
                            try {
                                classificationList=docxFile.getProperties()
                                        .getCustomProperties()
                                        .getProperty("classification"+Integer.toString(i)).getLpwstr();
                                jsonstrs.add(classificationList);
                            } catch (Exception e) {
                                e.printStackTrace();
                                break;
                            }
                            //System.out.println(classificationList.length());

                        }
                        String classification = "";
                        for(int j=0;j<jsonstrs.size();j++)
                        {
                            classification=classification+jsonstrs.get(j);
                        }
                        classification=classification.replace("_x000d_","");
                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);
                        JSONObject json = JSONObject.parseObject(jsonstra);
                        // 获取文档自定义属性
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
                        if (propList.contains("accessDescription")) {
                            accessDescription = json.getString("accessDescription");
                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围

                            //if(accessScope.containsKey("accessList") && (JSONArray)accessScope.get("accessList")){
                                accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                                try{
                                    accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                                } catch (Exception e) {
                                    //e.printStackTrace();

                                }

                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                        .get("basisDescription");// 定密依据详情
                                basisDescription = basisDescriptionArr;
                            } catch (Exception e) {
                                //e.printStackTrace();
                            }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }
                        if (propList.contains("basisType")) {
                            basisType = json.getInteger("basisType");
                        }
                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        if (!lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;

                        }else if (!createTime.equals(createTimestr)) {
                            ret = -3;

                        }else {
                            ret = 0;
                        }

                    } catch (Exception e) {
                        e.printStackTrace();

                    }
                }
                else if ("dps".equals(fileExt)) {
                    HSLFSlideShow dpsFile = new HSLFSlideShow(fis);

                    SummaryInformation summary = dpsFile.getSummaryInformation();
                    Date getfilecreateTime = dpsFile.getSummaryInformation().getCreateDateTime();
                    Date getfilelastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(getfilecreateTime);
                    String lastSaveTimestr = dateFormat.format(getfilelastSaveTime);


                    try {
                        DocumentSummaryInformation summaryinfomation = dpsFile.getDocumentSummaryInformation();
                        CustomProperties customproperties = summaryinfomation.getCustomProperties();
                        List<String> jsonstrs=new ArrayList<>();
                        for (int i=0;i<customproperties.size();i++)
                        {
                            String classificationList=null;
                            classificationList=(String) customproperties.get("classification"+Integer.toString(i));
							if(classificationList==null)
                                break;
							jsonstrs.add(classificationList);
                        }
                        String classification = "";
                        for(int j=0;j<jsonstrs.size();j++)
                        {
                            classification=classification+jsonstrs.get(j);
                        }
                        classification=classification.replace("_x000d_","");

                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);

                        JSONObject json = JSONObject.parseObject(jsonstra);
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
                        if (propList.contains("accessDescription")) {
                            accessDescription = json.getString("accessDescription");
                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                            accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                            try{
                                accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                            } catch (Exception e) {
                                //e.printStackTrace();
                            }
                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                            .get("basisDescription");// 定密依据详情
                                    basisDescription = basisDescriptionArr;
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }
                        if (propList.contains("basisType")) {
                            basisType = json.getInteger("basisType");
                        }
                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        if (!lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;
                        }else if (!createTime.equals(createTimestr)) {
                            ret = -3;
                        } else {
                            ret = 0;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                else if ("d0cf11e0".equals(versionValue) && ("ppt".equals(fileExt) || "pptx".equals(fileExt))) {
                    HSLFSlideShow pptFile = new HSLFSlideShow(fis);

                    SummaryInformation summary = pptFile.getSummaryInformation();
                    Date getfilecreateTime = pptFile.getSummaryInformation().getCreateDateTime();
                    Date getfilelastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(getfilecreateTime);
                    String lastSaveTimestr = dateFormat.format(getfilelastSaveTime);

                    try {
                        DocumentSummaryInformation summaryinfomation = pptFile.getDocumentSummaryInformation();
                        CustomProperties customproperties = summaryinfomation.getCustomProperties();
                        List<String> jsonstrs=new ArrayList<>();
                        for (int i=0;i<customproperties.size();i++)
                        {
                            String classificationList=null;
                            classificationList=(String) customproperties.get("classification"+Integer.toString(i));
							if(classificationList==null)
                                break;
                            jsonstrs.add(classificationList);
                        }
                        String classification = "";
                        for(int j=0;j<jsonstrs.size();j++)
                        {
                            classification=classification+jsonstrs.get(j);
                        }
                        classification=classification.replace("_x000d_","");

                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);

                        JSONObject json = JSONObject.parseObject(jsonstra);
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
//                        if (propList.contains("accessDescription")) {
//                            accessDescription = json.getString("accessDescription");
//                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                            accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                            try{
                                accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                            } catch (Exception e) {
                                //e.printStackTrace();
                            }
                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                            .get("basisDescription");// 定密依据详情
                                    basisDescription = basisDescriptionArr;
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }
                        if (propList.contains("basisType")) {
                            basisType = json.getInteger("basisType");
                        }
                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        if (!lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;
                        } else if (!createTime.equals(createTimestr)) {
                            ret = -3;

                        }else {
                            ret = 0;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
                else if ("504b0304".equals(versionValue) && ("ppt".equals(fileExt) || "pptx".equals(fileExt))) {

                    XMLSlideShow pptxFile = new XMLSlideShow(fis);

                    Date getfilecreateTime = pptxFile.getProperties().getCoreProperties().getCreated();
                    Date getfilelastSaveTime = pptxFile.getProperties().getCoreProperties().getModified();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(getfilecreateTime);
                    String lastSaveTimestr = dateFormat.format(getfilelastSaveTime);
                    try {
                        List<String> jsonstrs=new ArrayList<>();
                        for (int i=0;i<10;i++)
                        {
                            String classificationList=null;
                            try {
                                classificationList=pptxFile.getProperties()
                                        .getCustomProperties()
                                        .getProperty("classification"+Integer.toString(i)).getLpwstr();
                            } catch (Exception e) {
                                e.printStackTrace();
                                break;
                            }
                            jsonstrs.add(classificationList);

                        }
                        String classification = "";
                        for(int j=0;j<jsonstrs.size();j++)
                        {
                            classification=classification+jsonstrs.get(j);
                        }
                        classification=classification.replace("_x000d_","");
                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);
                        JSONObject json = JSONObject.parseObject(jsonstra);
                        // 获取文档自定义属性
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
//                        if (propList.contains("accessDescription")) {
//                            accessDescription = json.getString("accessDescription");
//                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                            accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                            try{
                                accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                            } catch (Exception e) {
                                //e.printStackTrace();
                            }
                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                            .get("basisDescription");// 定密依据详情
                                    basisDescription = basisDescriptionArr;
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }
                        if (propList.contains("basisType")) {
                            basisType = json.getInteger("basisType");
                        }
                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        if (!lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;

                        }else if (!createTime.equals(createTimestr)) {
                            ret = -3;

                        } else {
                            ret = 0;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
                else if ("wps".equals(fileExt)) {
                    HWPFDocument wpsfile = new HWPFDocument(fis);

                    SummaryInformation summary = wpsfile.getSummaryInformation();
                    Date getfilecreateTime = wpsfile.getSummaryInformation().getCreateDateTime();
                    Date getfilelastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(getfilecreateTime);
                    String lastSaveTimestr = dateFormat.format(getfilelastSaveTime);

                    try {
                        DocumentSummaryInformation summaryinfomation = wpsfile.getDocumentSummaryInformation();
                        CustomProperties customproperties = summaryinfomation.getCustomProperties();
                        List<String> jsonstrs=new ArrayList<>();
                        for (int i=0;i<customproperties.size();i++)
                        {
                            String classificationList=null;
                            classificationList=(String) customproperties.get("classification"+Integer.toString(i));
							if(classificationList==null)
                                break;
                            jsonstrs.add(classificationList);
                        }
                        String classification = "";
                        for(int j=0;j<jsonstrs.size();j++)
                        {
                            classification=classification+jsonstrs.get(j);
                        }
                        classification=classification.replace("_x000d_","");

                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);

                        JSONObject json = JSONObject.parseObject(jsonstra);
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
                        if (propList.contains("accessDescription")) {
                            accessDescription = json.getString("accessDescription");
                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                            accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                            try{
                                accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                            } catch (Exception e) {
                                //e.printStackTrace();
                            }
                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                            .get("basisDescription");// 定密依据详情
                                    basisDescription = basisDescriptionArr;
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }
                        if (propList.contains("basisType")) {
                            basisType = json.getInteger("basisType");
                        }
                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        if (!lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;

                        }else if (!createTime.equals(createTimestr)) {
                            ret = -3;

                        }else {
                            ret = 0;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
                else if ("d0cf11e0".equals(versionValue) && ("et".equals(fileExt) || "xls".equals(fileExt) || "xlsx".equals(fileExt))) {
                    HSSFWorkbook xlsfile = new HSSFWorkbook(fis);

                    SummaryInformation summary = xlsfile.getSummaryInformation();
                    Date getfilecreateTime = xlsfile.getSummaryInformation().getCreateDateTime();
                    Date getfilelastSaveTime = summary.getLastSaveDateTime();
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = dateFormat.format(getfilecreateTime);
                    String lastSaveTimestr = dateFormat.format(getfilelastSaveTime);


                    try {
                        DocumentSummaryInformation summaryinfomation = xlsfile.getDocumentSummaryInformation();
                        CustomProperties customproperties = summaryinfomation.getCustomProperties();
                        List<String> jsonstrs=new ArrayList<>();
                        for (int i=0;i<customproperties.size();i++)
                        {
                            String classificationList=null;
                            classificationList=(String) customproperties.get("classification"+Integer.toString(i));
                            if(classificationList==null)
                                break;
                            jsonstrs.add(classificationList);
                        }
                        String classification = "";
                        for(int j=0;j<jsonstrs.size();j++)
                        {
                            classification=classification+jsonstrs.get(j);
                        }
                        classification=classification.replace("_x000d_","");

                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);

                        JSONObject json = JSONObject.parseObject(jsonstra);
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
                        if (propList.contains("accessDescription")) {
                            accessDescription = json.getString("accessDescription");
                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                            accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                            try{
                                accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                            } catch (Exception e) {
                                //e.printStackTrace();
                            }
                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                            .get("basisDescription");// 定密依据详情
                                    basisDescription = basisDescriptionArr;
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }
                        if (propList.contains("basisType")) {
                            basisType = json.getInteger("basisType");
                        }
                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        if (!lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;
                        }else if (!createTime.equals(createTimestr)) {
                            ret = -3;

                        } else {
                            ret = 0;
                        }

                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
                else if (!"d0cf11e0".equals(versionValue) && ("et".equals(fileExt) || "xls".equals(fileExt) || "xlsx".equals(fileExt))) {


                    // {
                    // 声明授权
                    InputStream AsposeLicenseFile = new ClassPathResource("license.xml").getInputStream();
                    License license = new License();
                    license.setLicense(AsposeLicenseFile);

                    Workbook workbook = new Workbook(filePath);
                    CustomDocumentPropertyCollection customDocumentPropertyCollection = workbook.getWorksheets()
                            .getCustomDocumentProperties();

                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    String createTimestr = "";
                    String lastSaveTimestr = "";

                    try {
                        List<String> jsonstrs=new ArrayList<>();
                        for (int i=0;i<customDocumentPropertyCollection.getCount();i++)
                        {
                            String classificationList=null;
                           try {
                                classificationList = customDocumentPropertyCollection
                                        .get("classification"+Integer.toString(i))
                                        .toString();
                            } catch (Exception e) {
                                e.printStackTrace();
                                break;
                            }
//                            classificationList=poixmlProperties
//                                    .getCustomProperties()
//                                    .getProperty("classification"+Integer.toString(i)).getLpwstr();
                            jsonstrs.add(classificationList);
                        }
                        String classification = "";
                        for(int j=0;j<jsonstrs.size();j++)
                        {
                            classification=classification+jsonstrs.get(j);
                        }
                        classification=classification.replace("_x000d_","");
                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);
                        JSONObject json = JSONObject.parseObject(jsonstra);
                        // 获取文档自定义属性
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
                        if (propList.contains("accessDescription")) {
                            accessDescription = json.getString("accessDescription");
                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                            accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                            try{
                                accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                            } catch (Exception e) {
                                //e.printStackTrace();
                            }
                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                            .get("basisDescription");// 定密依据详情
                                    basisDescription = basisDescriptionArr;
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }

                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        if (!lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;
                        }else if (!createTime.equals(createTimestr)) {
                            ret = -3;

                        } else {
                            ret = 0;
                        }

                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                    AsposeLicenseFile.close();
                    // } add by liushen

//                    XSSFWorkbook xlsxfile = new XSSFWorkbook(fis);
//                    Date getfilecreateTime = xlsxfile.getProperties().getCoreProperties().getCreated();
//                    Date getfilelastSaveTime = xlsxfile.getProperties().getCoreProperties().getModified();
//                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                    String createTimestr = dateFormat.format(getfilecreateTime);
//                    String lastSaveTimestr = dateFormat.format(getfilelastSaveTime);
//
//                    try {
//                        List<String> jsonstrs=new ArrayList<>();
//                        for (int i=0;i<2;i++)
//                        {
//                            String classificationList=null;
//                            classificationList=xlsxfile.getProperties()
//                                    .getCustomProperties()
//                                    .getProperty("classification"+Integer.toString(i)).getLpwstr();
//                            jsonstrs.add(classificationList);
//
//                        }
//                        String classification = "";
//                        for(int j=0;j<jsonstrs.size();j++)
//                        {
//                            classification=classification+jsonstrs.get(j);
//                        }
//                        classification=classification.replace("_x000d_","");
//                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
//                        String jsonstra = encryptByXor(jsonstr);
//                        JSONObject json = JSONObject.parseObject(jsonstra);
//                        // 获取文档自定义属性
//                        if (propList.contains("classificationLevel")) {
//                            classificationLevel = json.getInteger("classificationLevel");
//                        }
//                        if (propList.contains("classificationPeriod")) {
//                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
//                            classificationPeriod = classificationDuration.getString("classificationPeriod");
//                        }
//                        if (propList.contains("declassifiedTime")) {
//                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
//                            declassifiedTime = classificationDuration.getString("declassifiedTime");
//                        }
//                        if (propList.contains("durationDescription")) {
//                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
//                            durationDescription = classificationDuration.getString("durationDescription");
//                        }
//                        if (propList.contains("classifiedTime")) {
//                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
//                            classifiedTime = classificationDuration.getString("classifiedTime");
//                        }
//                        if (propList.contains("lastSaveTime")) {
//                            lastSaveTime = json.getString("lastSaveTime");
//                        }
//                        if (propList.contains("createTime")) {
//                            createTime = json.getString("createTime");
//                        }
//                        if (propList.contains("accessDescription")) {
//                            accessDescription = json.getString("accessDescription");
//                        }
//                        if (propList.contains("accessList")) {
//                            accessList = json.getString("accessList");
//                        }
//                        if (propList.contains("classificationStatus")) {
//                            classificationStatus = json.getInteger("classificationStatus");
//                        }
//                        if (propList.contains("basisDescription")) {
//                            basisDescription = json.getString("basisDescription");
//                        }
//                        if (propList.contains("basisType")) {
//                            basisType = json.getInteger("basisType");
//                        }
//                        if (propList.contains("classifiedOrganization")) {
//                            classifiedOrganization = json.getString("classifiedOrganization");
//                        }
//                        if (propList.contains("drafter")) {
//                            drafter = json.getString("drafter");
//                        }
//                        if (propList.contains("classifiedPerson")) {
//                            classifiedPerson = json.getString("classifiedPerson");
//                        }
//                        if (propList.contains("issuer")) {
//                            issuer = json.getString("issuer");
//                        }
//                        if (propList.contains("classificationIdentifier")) {
//                            classificationIdentifier = json.getString("classificationIdentifier");
//                        }
//                        if (propList.contains("classificationHistory")) {
//                            classificationHistory = json.getString("classificationHistory");
//                        }
//                        if (propList.contains("extensions")) {
//                            extensions = json.getString("extensions");
//                        }
//                        if (!lastSaveTime.equals(lastSaveTimestr)) {
//                            ret = 1;
//                        }else if (!createTime.equals(createTimestr)) {
//                            ret = -3;
//
//                        } else {
//                            ret = 0;
//                        }
//
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
                }
                else if ("pdf".equals(fileExt)) {
                    try {
                        fis.close();
                        PDDocument document = PDDocument.load(new File(filePath));

                        PDDocumentInformation info = document.getDocumentInformation();
                        //获取文件创建时间和最后一次修改时间
                        Calendar lastSaveTimec = info.getModificationDate();
                        Calendar creatTimec = info.getCreationDate();



                        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        String lastSaveTimestr = dateFormat.format(lastSaveTimec.getTime());
                        String createTimestr = dateFormat.format(creatTimec.getTime());


                        //获取自定义属性
                        String classification = info.getCustomMetadataValue("classification");
                        document.close();

                        String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                        String jsonstra = encryptByXor(jsonstr);
                        JSONObject json = JSONObject.parseObject(jsonstra);
                        // 获取文档自定义属性
                        if (propList.contains("classificationLevel")) {
                            classificationLevel = json.getInteger("classificationLevel");
                        }
                        if (propList.contains("classificationPeriod")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classificationPeriod = classificationDuration.getString("classificationPeriod");
                        }
                        if (propList.contains("declassifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            declassifiedTime = classificationDuration.getString("declassifiedTime");
                        }
                        if (propList.contains("durationDescription")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            durationDescription = classificationDuration.getString("durationDescription");
                        }
                        if (propList.contains("classifiedTime")) {
                            JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                            classifiedTime = classificationDuration.getString("classifiedTime");
                        }
                        if (propList.contains("lastSaveTime")) {
                            lastSaveTime = json.getString("lastSaveTime");
                        }
                        if (propList.contains("createTime")) {
                            createTime = json.getString("createTime");
                        }
                        if (propList.contains("accessDescription")) {
                            accessDescription = json.getString("accessDescription");
                        }
                        if (propList.contains("accessList")) {
                            JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                            accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                            try{
                                accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                            } catch (Exception e) {
                                //e.printStackTrace();
                            }
                        }
                        if (propList.contains("classificationStatus")) {
                            classificationStatus = json.getInteger("classificationStatus");
                        }
                        if (propList.contains("classificationBasis")) {
                            JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                            if(null!=classificationBasis){
                                try{
                                    JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                            .get("basisDescription");// 定密依据详情
                                    basisDescription = basisDescriptionArr;
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }

                                basisType = (Integer) classificationBasis
                                        .get("basisType");// 依据类型
                            }
                        }
                        if (propList.contains("basisType")) {
                            basisType = json.getInteger("basisType");
                        }
                        if (propList.contains("classifiedOrganization")) {
                            classifiedOrganization = json.getString("classifiedOrganization");
                        }
                        if (propList.contains("drafter")) {
                            drafter = json.getString("drafter");
                        }
                        if (propList.contains("classifiedPerson")) {
                            classifiedPerson = json.getString("classifiedPerson");
                        }
                        if (propList.contains("issuer")) {
                            issuer = json.getString("issuer");
                        }
                        if (propList.contains("classificationIdentifier")) {
                            classificationIdentifier = json.getString("classificationIdentifier");
                        }
                        if (propList.contains("classificationHistory")) {
                            classificationHistory = json.getString("classificationHistory");
                        }
                        if (propList.contains("extensions")) {
                            extensions = json.getString("extensions");
                        }
                        //if (classifiedTime!=null && !lastSaveTimestr.equals("") && !(classifiedTime.substring(0,8)).equals((lastSaveTimestr.substring(0,8))))
                        if (lastSaveTime != null && !lastSaveTimestr.equals("") && !lastSaveTime.equals(lastSaveTimestr)) {
                            ret = 1;
                        } else if (!createTime.equals(createTimestr)) {
                            ret = -3;

                        }else {
                            ret = 0;
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                else if ("ofd".equals(fileExt)) {
                    try {
                        fis.close();
                        Path srcP = Paths.get(filePath);
                        try (OFDReader reader = new OFDReader(srcP)) {
                            OFDDir ofdDir = reader.getOFDDir();
                            // CT_DocInfo docInfo = reader.getOFDDir().getOfd().getDocBody().getDocInfo();

                            OFD ofd = ofdDir.getOfd();
                            DocBody docBody = ((OFD) ofd).getDocBody();
                            CT_DocInfo docInfo = docBody.getDocInfo();
                            // docInfo.setCustomDatas();
                            //获取自定义属性
                            String classification = docInfo.getCustomDatas().getCustomDataValue("classification");
                            reader.close();

                            String jsonstr = new String(new sun.misc.BASE64Decoder().decodeBuffer(classification));
                            String jsonstra = encryptByXor(jsonstr);
                            JSONObject json = JSONObject.parseObject(jsonstra);
                            // 获取文档自定义属性
                            if (propList.contains("classificationLevel")) {
                                classificationLevel = json.getInteger("classificationLevel");
                            }
                            if (propList.contains("classificationPeriod")) {
                                JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                                classificationPeriod = classificationDuration.getString("classificationPeriod");
                            }
                            if (propList.contains("declassifiedTime")) {
                                JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                                declassifiedTime = classificationDuration.getString("declassifiedTime");
                            }
                            if (propList.contains("durationDescription")) {
                                JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                                durationDescription = classificationDuration.getString("durationDescription");
                            }
                            if (propList.contains("classifiedTime")) {
                                JSONObject classificationDuration = json.getJSONObject("classificationDuration");
                                classifiedTime = classificationDuration.getString("classifiedTime");
                            }
                            if (propList.contains("lastSaveTime")) {
                                lastSaveTime = json.getString("lastSaveTime");
                            }
                            if (propList.contains("createTime")) {
                                createTime = json.getString("createTime");
                            }
                            if (propList.contains("accessDescription")) {
                                accessDescription = json.getString("accessDescription");
                            }
                            if (propList.contains("accessList")) {
                                JSONObject accessScope = (JSONObject) json.get("accessScope");// 知悉范围
                                accessDescription = (String) accessScope.get("accessDescription");// 知悉描述
                                try{
                                    accessList = (JSONArray) accessScope.get  ("accessList");// 列举式知悉3
                                } catch (Exception e) {
                                    //e.printStackTrace();
                                }
                            }
                            if (propList.contains("classificationStatus")) {
                                classificationStatus = json.getInteger("classificationStatus");
                            }
                            if (propList.contains("classificationBasis")) {
                                JSONObject classificationBasis = (JSONObject) json.get("classificationBasis");// 定密依据
                                if(null!=classificationBasis){
                                    try{
                                        JSONArray basisDescriptionArr = (JSONArray) classificationBasis
                                                .get("basisDescription");// 定密依据详情
                                        basisDescription = basisDescriptionArr;
                                    } catch (Exception e) {
                                        //e.printStackTrace();
                                    }

                                    basisType = (Integer) classificationBasis
                                            .get("basisType");// 依据类型
                                }
                            }
                            if (propList.contains("basisType")) {
                                basisType = json.getInteger("basisType");
                            }
                            if (propList.contains("classifiedOrganization")) {
                                classifiedOrganization = json.getString("classifiedOrganization");
                            }
                            if (propList.contains("drafter")) {
                                drafter = json.getString("drafter");
                            }
                            if (propList.contains("classifiedPerson")) {
                                classifiedPerson = json.getString("classifiedPerson");
                            }
                            if (propList.contains("issuer")) {
                                issuer = json.getString("issuer");
                            }
                            if (propList.contains("classificationIdentifier")) {
                                classificationIdentifier = json.getString("classificationIdentifier");
                            }
                            if (propList.contains("classificationHistory")) {
                                classificationHistory = json.getString("classificationHistory");
                            }
                            if (propList.contains("extensions")) {
                                extensions = json.getString("extensions");
                            }
                            //if (classifiedTime!=null && !lastSaveTimestr.equals("") && !(classifiedTime.substring(0,8)).equals((lastSaveTimestr.substring(0,8))))
//                            if (lastSaveTime != null && !lastSaveTimestr.equals("") && !lastSaveTime.equals(lastSaveTimestr)) {
//                                ret = 1;
//                            } else {
//                                ret = 0;
//                            }
                            if(classification != null && classification != "" && json != null &&  classificationLevel != null)
                            {
                                ret = 0;
                            }

                        } catch (DocumentException e) {
                            throw new RuntimeException(e);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                }
                fis.close();
            } catch (Exception e) {
                e.printStackTrace();
                fis.close();
                Property property = new Property();
                property.setRet(ret);
                String jsonStr = JSON.toJSONString(property);
                return jsonStr;
            }
        } else {
            ret = -2;
            fis.close();
            Property property = new Property();
            property.setRet(ret);
            String jsonStr = JSON.toJSONString(property);
            return jsonStr;
        }


        //密级属性
        Property property = new Property();
        property.setClassificationLevel(classificationLevel);


//        property.setCreateTime(createTime);
//        property.setLastSaveTime(lastSaveTime);
        property.setRet(ret);
        //保密期限

        if (null != classificationPeriod || null != declassifiedTime || null != durationDescription || null != classifiedTime) {
            ClassificationDuration classificationDuration = new ClassificationDuration();
            classificationDuration.setClassificationPeriod(classificationPeriod);
            classificationDuration.setDeclassifiedTime(declassifiedTime);
            classificationDuration.setDurationDescription(durationDescription);
            classificationDuration.setClassifiedTime(classifiedTime);
            property.setClassificationDuration(classificationDuration);
        }
        //定密依据
        if (null != basisDescription || null != basisType) {
            ClassificationBasis classificationBasis = new ClassificationBasis();
            classificationBasis.setBasisDescription(basisDescription);
            classificationBasis.setBasisType(basisType);
            property.setClassificationBasis(classificationBasis);
        }
        //知悉范围
        if (null != accessDescription || null != accessList) {
            AccessScope accessScope = new AccessScope();
            accessScope.setAccessDescription(accessDescription);
            accessScope.setAccessList(accessList);
            property.setAccessScope(accessScope);
        }
        //密级属性
//        property.setClassificationPeriod(classificationPeriod);
//        property.setDeclassifiedTime(declassifiedTime);
//        property.setDurationDescription(durationDescription);
//        property.setClassifiedTime(classifiedTime);
//        property.setAccessDescription(accessDescription);
//        property.setAccessList(accessList);
        property.setClassificationStatus(classificationStatus);
//        property.setBasisDescription(basisDescription);
//        property.setBasisType(basisType);
        property.setClassifiedOrganization(classifiedOrganization);
        property.setDrafter(drafter);
        property.setClassifiedPerson(classifiedPerson);
        property.setIssuer(issuer);
        property.setClassificationIdentifier(classificationIdentifier);
        property.setClassificationHistory(classificationHistory);
        property.setExtensions(extensions);

        String jsonStr = JSON.toJSONString(property);
        System.out.println(property + "jsonStr=============" + jsonStr);
        return jsonStr;
    }


//    public static String delFileProperty(String filePath) {
//        try {
//            //filePath = new String(new sun.misc.BASE64Decoder().decodeBuffer(filePath));
//            System.out.println("filePath============"+filePath);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//        File inputFile = new File(filePath);
//
//        //获取配置文件里面的相关信息
//        try {
//            Properties properties = PropertiesLoaderUtils.loadAllProperties("app.properties");
//            //文件类型
//            filetype = new String(properties.getProperty("file.type").getBytes("iso-8859-1"),"gbk");
//            //文件属性参数
//            fileprop = new String(properties.getProperty("file.prop").getBytes("iso-8859-1"),"gbk");
//        }catch (Exception e){
//            e.printStackTrace();
//        }
//        String fileName = inputFile.getName();
//        System.out.println("fileName=============" + fileName);
//        String fileExt = fileName.substring(fileName.lastIndexOf(".") + 1);
//        System.out.println("fileExt=============" + fileExt);
//        String[] types = filetype.split(",");
//        List<String> typeList = Arrays.asList(types);
//        //各类文件处理
//        if (typeList.contains(fileExt)) {
//            try {
//                System.out.println("AbsolutePath=============" + inputFile.getAbsolutePath());
//                FileInputStream fileInputStream = new FileInputStream(inputFile);
//                //判断文件版本
//                byte[] b = new byte[4];
//                fileInputStream.read(b,0,b.length);
//                String versionValue = bytesToHexString(b);
//                fileInputStream.close();
//                FileInputStream fis = new FileInputStream(inputFile);
//                //03版本文件
//                if (("d0cf11e0".equals(versionValue) &&("wps".equals(fileExt) || "docx".equals(fileExt) ||"doc".equals(fileExt) ))) {// 处理doc格式的文档，处理wps格式也可以使用
//
//                    System.out.println("aaaaaaaaaaaaaaaaaa=============" + fileExt);
//                    Document doc = new Document();
//                    doc.loadFromFile(filePath);
//
//                    doc.getCustomDocumentProperties().remove("classificationLevel");
//                    doc.getCustomDocumentProperties().remove("classificationPeriod");
//                    doc.getCustomDocumentProperties().remove("classifiedTime");
//                    doc.getCustomDocumentProperties().remove("declassifiedTime");
//                    doc.getCustomDocumentProperties().remove("durationDescription");
//
//
//                    doc.saveToFile(filePath, FileFormat.Auto);
//                    doc.dispose();
//
//                }
//                else if (("d0cf11e0".equals(versionValue) &&("et".equals(fileExt) || "xls".equals(fileExt) ||"xlsx".equals(fileExt) ))) {// 处理xls格式的文档，处理xlsx格式也可以使用
//
//                    System.out.println("bbbbbbbbbbbbbbbbbbbbb=============" + fileExt);
//
//                    Workbook wb = new Workbook();
//                    wb.loadFromFile(filePath);
//
//                    wb.getCustomDocumentProperties().remove("classificationLevel");
//                    wb.getCustomDocumentProperties().remove("classificationPeriod");
//                    wb.getCustomDocumentProperties().remove("classifiedTime");
//                    wb.getCustomDocumentProperties().remove("declassifiedTime");
//                    wb.getCustomDocumentProperties().remove("durationDescription");
//
//
//                    wb.saveToFile(filePath, ExcelVersion.Version97to2003);
//                    wb.dispose();
//
//
//                } else if (("d0cf11e0".equals(versionValue) && ("ppt".equals(fileExt) || "pptx".equals(fileExt)|| "dps".equals(fileExt)))) {
//
//                    System.out.println("cccccccccccccccccccc=============" + fileExt);
//                    Presentation presentation = new Presentation();
//                    presentation.loadFromFile(filePath);
//
//
//                    //doc.getCustomDocumentProperties().add("classificationLevel","123");
//                    //doc.getCustomDocumentProperties().add("classifiedTime","否");
//
//
//                    //通过方法删除指定属性内容
//                    //doc.getCustomDocumentProperties().remove("classificationLevel");
//                    presentation.getDocumentProperty().remove("classificationLevel");
//                    presentation.getDocumentProperty().remove("classificationPeriod");
//                    presentation.getDocumentProperty().remove("classifiedTime");
//                    presentation.getDocumentProperty().remove("declassifiedTime");
//                    presentation.getDocumentProperty().remove("durationDescription");
//
//                    //保存文档
//                    presentation.saveToFile(filePath, com.spire.presentation.FileFormat.AUTO);
//                    presentation.dispose();
//
//                }
//
//            } catch (Exception e) {
//                e.printStackTrace();
//                return "-2";
//            }
//        } else {
//            return "-1";
//        }
//        return "0";
//    }


}
